package com.gzhryc.shared_device.oem.code.order.services;

import com.gzhryc.common.logging.Logger;
import com.gzhryc.jdbc.Conditions;
import com.gzhryc.jdbc.MultiDBTools;
import com.gzhryc.shared_device.oem.code.order.dao.BXSCNShopOrderUserDao;
import com.gzhryc.shared_device.oem.code.order.dao.models.BXSCNShopOrderUser;
import com.gzhryc.shared_device.oem.code.order.services.dto.BXSCNShopOrderUserSearch;

import java.sql.SQLException;
import java.util.Date;
import java.util.List;

public class BXSCNShopOrderUserService {

    static Logger log = Logger.getLogger(BXSCNShopOrderUserService.class);

    public static BXSCNShopOrderUserService self(Date date) {
        return MultiDBTools.getService(BXSCNShopOrderUserService.class, date);
    }

    public static BXSCNShopOrderUserService self(String jdbcKey,Date date) {
        return MultiDBTools.getService(jdbcKey,BXSCNShopOrderUserService.class, date);
    }

    BXSCNShopOrderUserDao dao;

    public BXSCNShopOrderUserService(String jdbcKey,Date date) {
        dao = new BXSCNShopOrderUserDao(jdbcKey,date);
    }

    public List<BXSCNShopOrderUser> findJoinBySearch(BXSCNShopOrderUserSearch search, Integer pageNo, Integer pageLimit){
        Conditions conditions = dao.buildConditions(search);
        conditions.and().likeBoth("tradeNo",search.getTrim()).or().likeBoth("placeName",search.getTrim());
        conditions.and().is("shopOrder.portable_battery_sn",search.getPortableBatterySn());
        conditions.and().in("shopOrder.state",search.getDeviceOrderStateList());
        conditions.and().is("shopOrder.state",search.getDeviceOrderState());
        conditions.and().not("shopOrder.pay_state",search.getNotPayState());
        conditions.and().is("shopOrder.pay_state",search.getPayState());
        conditions.desc("createDate");
        try {
            return dao.findJoinByCondition(conditions,pageNo,pageLimit);
        } catch (SQLException e) {
            log.error(e.getMessage(),e);
        }
        return null;
    }
}
